package com.csproj.dispatch.resource;

import com.codahale.metrics.annotation.Timed;
import com.csproj.dispatch.domain.ProductDetailInfo;
import com.csproj.dispatch.service.ProductDetailInfoService;
import com.csproj.dispatch.service.dto.ProductDetailInfoDTO;
import com.csproj.siiat.base.common.dto.BaseDTO;
import com.csproj.system.domain.UserInfo;
import com.csproj.system.service.SysLogsService;
import com.csproj.system.service.UserInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * REST controller for managing ProductDetailInfo.
 * 商品明细信息controlleer
 */
@RestController
@RequestMapping("/api/center/pdi")
public class ProductDetailInfoResource {

    private final Logger log = LoggerFactory.getLogger(ProductDetailInfoResource.class);

    private static final String ENTITY_NAME = "productDetailInfo";

    private final ProductDetailInfoService productDetailInfoService;
    private final UserInfoService userInfoService;
    private final SysLogsService sysLogsService;
    public ProductDetailInfoResource(ProductDetailInfoService productDetailInfoService,UserInfoService userInfoService,SysLogsService sysLogsService) {
        this.productDetailInfoService = productDetailInfoService;
        this.sysLogsService = sysLogsService;
        this.userInfoService = userInfoService;
    }

    /**
     * 批量插入商品明细信息
     * @param productDetailInfoDTOS 商品明细信息列表
     * @return
     */
    @PostMapping("/productDetailInfo")
    @Timed
    public BaseDTO insertDetails(@RequestBody List<ProductDetailInfoDTO> productDetailInfoDTOS){
        UserInfo userInfo = userInfoService.getCurrentUser();
        sysLogsService.saveForGet("", userInfo.getName()+":user_create_product_info","");
        return productDetailInfoService.saveDetails(productDetailInfoDTOS);
    }

    /**
     * 更新商品明细信息
     * @param productDetailInfoDTO 商品明细信息
     * @param id 商品明细主键
     * @return
     */
    @PutMapping("/productDetailInfo/{id}")
    @Timed
    public BaseDTO updateDetailById(@RequestBody ProductDetailInfoDTO productDetailInfoDTO, @PathVariable String id) {
        UserInfo userInfo = userInfoService.getCurrentUser();
        sysLogsService.saveForGet("", userInfo.getName()+":user_update_product_info","");
        return productDetailInfoService.updateDetailById(id, productDetailInfoDTO);
    }

    /**
     * 删除商品明细
     * @param id 商品明细主键
     * @return
     */
    @DeleteMapping("/productDetailInfo/{id}")
    @Timed
    public BaseDTO deleteDetailById(@PathVariable String id) {
        return productDetailInfoService.deleteDetailById(id);
    }

}